package com.my.controller;

import com.alibaba.fastjson2.JSONObject;
import com.my.request.AppChatAddAppIdReq;
import com.my.request.AppChatAddReq;
import com.my.result.ChatMessageResult;
import com.my.result.Result;
import com.my.util.AccessTokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author sjx
 * @date 2025/2/24 9:53
 */
@Slf4j
@RestController
@RequestMapping("/wecomChat")
public class WecomChatController {

    @Value("${wecom.appId}")
    private String appId;

    @PostMapping("/addAppIdByAppChat")
    public Result<Void> addAppIdByAppChat(@RequestBody @Valid AppChatAddAppIdReq request) {
        AccessTokenUtil.addAppIdByAppchatId(request.getChatId(),appId);
        return Result.ok();
    }

    @PostMapping("/addChat")
    public Result<Void> addChat(@RequestBody @Valid AppChatAddReq request) {
        ChatMessageResult chatMessageResult = AccessTokenUtil.addChatId(request);
        log.info("返回结果:{}", JSONObject.toJSONString(chatMessageResult));
        return Result.ok();
    }

}
